﻿using System.Collections.Generic;
using System.Linq;
using NTTDATA.BEENChina.ResultCertification.Result;
using NTTDATA.BEENChina.ResultCertification.Split; 
namespace NTTDATA.BEENChina.ResultCertification.Checker
{
    public class VerfityMulitResult:Verfity
    {
        private EnumRank _compareRankX = EnumRank.Final, _compareRankY = EnumRank.Final;

        public EnumRank CompareRankX
        {
            get { return _compareRankX; }
            set { _compareRankX = value; }
        }

        public EnumRank CompareRankY
        {
            get { return _compareRankY; }
            set { _compareRankY = value; }
        }

        /// <summary>
        /// modify 2013/11/11 change  !string.IsNullOrEmpty(y.EntryResult + y.EntryCommon)
        /// </summary>
        /// <returns></returns>
        public override bool Check()
        {
            var query = from x in ChildImageObject.OperatorEntryResults
                        from y in ChildImageObject.OperatorEntryResults
                        where x != y && y.Rank > x.Rank 
                              && !string.IsNullOrEmpty(x.EntryResult + x.EntryCommon) && !string.IsNullOrEmpty(y.EntryResult + y.EntryCommon)
                              && x.Rank != EnumRank.E && y.Rank!= EnumRank.E 
                        select new KeyValuePair<OpEntryResult, OpEntryResult>(x, y);
            
            List<KeyValuePair<OpEntryResult, OpEntryResult>> list = query.ToList();
            bool bResult  = list.Any(o => CheckResult(o.Key, o.Value));
           
            return bResult; 
        }

        private bool CheckResult(OpEntryResult x, OpEntryResult y)
        {
            Split.ISplit split = new SplitResult(ChildImageObject.CategorySetting);
            List<List<string>> splitResultX = split.GetSplitResult(x.EntryResult ).ToList();
            List<List<string>> splitResultY = split.GetSplitResult(y.EntryResult).ToList();

            CompareRankX = x.Rank;
            CompareRankY = y.Rank;
            
            return CheckResult(splitResultX, x.EntryCommon, splitResultY, y.EntryCommon);
        }

        public  virtual bool CheckResult(List<List<string>> result1, string entryCommon1, List<List<string>> result2, string entryCommon2)
        {
            return false;
        }

      
    

    }
}
